package com.le.tester.leetcode;

import com.le.tester.leetcode.common.TreeNode;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * currentTime:2022/3/10 9:36
 * description:二叉树的前序遍历
 */
public class PreOrderTraversal {
    public List<Integer> preOrderTraversal(TreeNode root) {

        List<Integer> resultList = new ArrayList<>();
        this.preOrder(root, resultList);
        return resultList;
    }

    public void preOrder(TreeNode root, List<Integer> integerList) {
        if (Objects.isNull(root)) {
            return;
        }
        integerList.add(root.val);
        this.preOrder(root.left, integerList);
        this.preOrder(root.right, integerList);
    }
}
